﻿namespace WpfSimpleCharttest
{
    using System;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using System.Linq;
    using System.Text;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    using System.Windows.Shapes;

    using De.LarsHildebrandt.WpfControls.WpfSimpleChart;

    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class WpfSimpleChartDemo : Window
    {
        #region Fields

        private ObservableCollection<ChartLegendItem> m_barLegend = new ObservableCollection<ChartLegendItem>();
        private ObservableCollection<ChartRow> m_barRows = new ObservableCollection<ChartRow>();
        private ObservableCollection<ChartLegendItem> m_pieLegend = new ObservableCollection<ChartLegendItem>();
        private ObservableCollection<ChartRow> m_pieRows = new ObservableCollection<ChartRow>();
        private ObservableCollection<ChartLegendItem> m_stackedLegend = new ObservableCollection<ChartLegendItem>();
        private ObservableCollection<StackedChartRow> m_stackedRows = new ObservableCollection<StackedChartRow>();

        #endregion Fields

        #region Constructors

        public WpfSimpleChartDemo()
        {
            PrepareBarChart();
            PreparePieChart();
            PrepareStackedChart();

            InitializeComponent();
        }

        #endregion Constructors

        #region Properties

        public ObservableCollection<ChartLegendItem> BarLegend
        {
            get { return m_barLegend; }
            set { m_barLegend = value; }
        }

        public ObservableCollection<ChartRow> BarRows
        {
            get { return m_barRows; }
            set { m_barRows = value; }
        }

        public ObservableCollection<StackedChartRow> StackedRows
        {
            get { return m_stackedRows; }
            set { m_stackedRows = value; }
        }

        public ObservableCollection<ChartLegendItem> PieLegend
        {
            get { return m_pieLegend; }
            set { m_pieLegend = value; }
        }

        public ObservableCollection<ChartRow> PieRows
        {
            get { return m_pieRows; }
            set { m_pieRows = value; }
        }

        public ObservableCollection<ChartLegendItem> StackedLegend
        {
            get { return m_stackedLegend; }
            set { m_stackedLegend = value; }
        }

        #endregion Properties

        #region Methods

        private void AddStackedChartRow(string caption, double value1, double value2, double value3, double value4, double value5)
        {
            StackedChartRow row;

            row = new StackedChartRow(caption);
            row.Values.Add(new ChartRow("Stacked-Value 1", value1, Colors.Green));
            row.Values.Add(new ChartRow("Stacked-Value 2", value2, Colors.Violet));
            row.Values.Add(new ChartRow("Stacked-Value 3", value3, Colors.Red));
            row.Values.Add(new ChartRow("Stacked-Value 4", value4, Colors.Yellow));
            row.Values.Add(new ChartRow("Stacked-Value 5", value5, Colors.DarkOrange));

            m_stackedRows.Add(row);
        }

        private void PrepareBarChart()
        {
            Random gen = new Random(DateTime.Now.Millisecond);

            m_barRows.Add(new ChartRow("Bar-Value 1", Convert.ToDouble(gen.Next(10)), Colors.Green));
            m_barRows.Add(new ChartRow("Bar-Value 2", Convert.ToDouble(gen.Next(10)), Colors.Violet));
            m_barRows.Add(new ChartRow("Bar-Value 3", Convert.ToDouble(gen.Next(10)), Colors.Red));
            m_barRows.Add(new ChartRow("Bar-Value 4", Convert.ToDouble(gen.Next(10)), Colors.Yellow));
            m_barRows.Add(new ChartRow("Bar-Value 5", Convert.ToDouble(gen.Next(10)), Colors.DarkOrange));

            m_barLegend.Clear();
            m_barLegend.Add(new ChartLegendItem("Bar-Value 1", Colors.Green));
            m_barLegend.Add(new ChartLegendItem("Bar-Value 2", Colors.Violet));
            m_barLegend.Add(new ChartLegendItem("Bar-Value 3", Colors.Red));
            m_barLegend.Add(new ChartLegendItem("Bar-Value 4", Colors.Yellow));
            m_barLegend.Add(new ChartLegendItem("Bar-Value 5", Colors.DarkOrange));
        }

        private void PreparePieChart()
        {
            Random gen = new Random(DateTime.Now.Millisecond);

            m_pieRows.Add(new ChartRow("Pie-Value 1", Convert.ToDouble(gen.Next(10)), Colors.Green));
            m_pieRows.Add(new ChartRow("Pie-Value 2", Convert.ToDouble(gen.Next(10)), Colors.Violet));
            m_pieRows.Add(new ChartRow("Pie-Value 3", Convert.ToDouble(gen.Next(10)), Colors.Red));
            m_pieRows.Add(new ChartRow("Pie-Value 4", Convert.ToDouble(gen.Next(10)), Colors.Yellow));
            m_pieRows.Add(new ChartRow("Pie-Value 5", Convert.ToDouble(gen.Next(10)), Colors.DarkOrange));

            m_pieLegend.Clear();
            m_pieLegend.Add(new ChartLegendItem("Pie-Value 1", Colors.Green));
            m_pieLegend.Add(new ChartLegendItem("Pie-Value 2", Colors.Violet));
            m_pieLegend.Add(new ChartLegendItem("Pie-Value 3", Colors.Red));
            m_pieLegend.Add(new ChartLegendItem("Pie-Value 4", Colors.Yellow));
            m_pieLegend.Add(new ChartLegendItem("Pie-Value 5", Colors.DarkOrange));
        }

        private void PrepareStackedChart()
        {
            AddStackedChartRow("Value 1", 2, 4, 6, 8, 10);
            AddStackedChartRow("Value 2", 12, 4, 2, 3, 1);
            AddStackedChartRow("Value 3", 1, 8, 1, 1, 1);
            AddStackedChartRow("Value 4", 1, 2, 3, 4, 5);
            AddStackedChartRow("Value 5", 5, 4, 3, 2, 1);


            m_stackedLegend.Clear();
            m_stackedLegend.Add(new ChartLegendItem("Stacked-Value 1", Colors.Green));
            m_stackedLegend.Add(new ChartLegendItem("Stacked-Value 2", Colors.Violet));
            m_stackedLegend.Add(new ChartLegendItem("Stacked-Value 3", Colors.Red));
            m_stackedLegend.Add(new ChartLegendItem("Stacked-Value 4", Colors.Yellow));
            m_stackedLegend.Add(new ChartLegendItem("Stacked-Value 5", Colors.DarkOrange));
        }

        #endregion Methods
    }
}